import {loginFhRequest} from './index'
export function getLoginCode() {
	return new Promise((resolve, reject) =>{
		wx.login({
			timeout: 1000,
			success(res) {
				resolve(res.code)
			},
			fail() {
				reject(err)
				console.log(err);
			}
		})
	})
}

// 发送code得到token
export function sendCode2Token(code) {
	return loginFhRequest.post('/login', { code })
}
// 检查token是否过期,传入header
export function checkToken(token) {
	return loginFhRequest.post('/auth', {}, {token})
}

// 检查session_key是否过期
export function checkSessionKey() {
	return new Promise((resolve,reject) => {
		wx.checkSession({
			success: () => {
				resolve(true)
			},
			fail: () => {
				reject(false);
			}
		})
	})
}

// 获取用户信息
export function getUserProfile() {
	return new Promise((resolve, reject) => {
		wx.getUserProfile({
			desc: 'Fhup',
			success:(res) => {
				resolve(res.userInfo)
			},
			fail:() => {
				wx.showToast({
					title: '您点击了拒绝~',
					icon:'error'
				})
			}
		})
	})
}